<template>
  <a-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="供应商编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'supplierCode', validatorRules.supplierCode]" placeholder="请输入供应商编号"></a-input>
        </a-form-item>
        <a-form-item label="生产订单编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'productionOrderId', validatorRules.productionOrderId]" placeholder="请输入生产订单编号"></a-input>
        </a-form-item>
        <a-form-item label="工单号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'workOrderCode', validatorRules.workOrderCode]" placeholder="请输入工单号"></a-input>
        </a-form-item>
        <a-form-item label="实验数据编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'testCode', validatorRules.testCode]" placeholder="请输入实验数据编号"></a-input>
        </a-form-item>
        <a-form-item label="厂内编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'plantCode', validatorRules.plantCode]" placeholder="请输入厂内编号"></a-input>
        </a-form-item>
        <a-form-item label="监测时间，供应商侧，格式：YYYY-MM-DD hh:mm:ss" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'checkTime', validatorRules.checkTime]" placeholder="请输入监测时间，供应商侧，格式：YYYY-MM-DD hh:mm:ss"></a-input>
        </a-form-item>
        <a-form-item label="有无功，填写有或无" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'power', validatorRules.power]" placeholder="请输入有无功，填写有或无"></a-input>
        </a-form-item>
        <a-form-item label="正反向，填写正或反" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'direction', validatorRules.direction]" placeholder="请输入正反向，填写正或反"></a-input>
        </a-form-item>
        <a-form-item label="合分元，单位是相，只填数值，不填写单位" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'yuan', validatorRules.yuan]" placeholder="请输入合分元，单位是相，只填数值，不填写单位"></a-input>
        </a-form-item>
        <a-form-item label="实验电压，单位是伏，只填数值不写单位" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'testingVoltage', validatorRules.testingVoltage]" placeholder="请输入实验电压，单位是伏，只填数值不写单位"></a-input>
        </a-form-item>
        <a-form-item label="测试电流，单位是安培，只填数值，不填写单位" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'testingCurrent', validatorRules.testingCurrent]" placeholder="请输入测试电流，单位是安培，只填数值，不填写单位"></a-input>
        </a-form-item>
        <a-form-item label="功率因数,供应商填写" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'powerFactor', validatorRules.powerFactor]" placeholder="请输入功率因数,供应商填写"></a-input>
        </a-form-item>
        <a-form-item label="平均误差，如-0.0222" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'averageError', validatorRules.averageError]" placeholder="请输入平均误差，如-0.0222"></a-input>
        </a-form-item>
        <a-form-item label="监测结论，0：合格，1：不合格" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'conclusion', validatorRules.conclusion]" placeholder="请输入监测结论，0：合格，1：不合格" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="创建时间/抓取时间，格式：YYYY-MM-DD" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'createTime', validatorRules.createTime]" placeholder="请输入创建时间/抓取时间，格式：YYYY-MM-DD"></a-input>
        </a-form-item>
        <a-form-item label="上传标志，默认1,1：未上传，0：已上传" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'ioflag', validatorRules.ioflag]" placeholder="请输入上传标志，默认1,1：未上传，0：已上传" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="jId" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'jId', validatorRules.jId]" placeholder="请输入jId" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="数据信息类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'infoTypeCode', validatorRules.infoTypeCode]" placeholder="请输入数据信息类型"></a-input>
        </a-form-item>
        <a-form-item label="抓取时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择抓取时间" v-decorator="[ 'grabTime', validatorRules.grabTime]" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import JDate from '@/components/jeecg/JDate'  
  
  export default {
    name: "ZxjEipDnbJbwccsdetailModal",
    components: { 
      JDate,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
        supplierCode:{rules: [{ required: true, message: '请输入供应商编号!' }]},
        productionOrderId:{rules: [{ required: true, message: '请输入生产订单编号!' }]},
        workOrderCode:{rules: [{ required: true, message: '请输入工单号!' }]},
        testCode:{rules: [{ required: true, message: '请输入实验数据编号!' }]},
        plantCode:{rules: [{ required: true, message: '请输入厂内编号!' }]},
        checkTime:{rules: [{ required: true, message: '请输入监测时间，供应商侧，格式：YYYY-MM-DD hh:mm:ss!' }]},
        power:{rules: [{ required: true, message: '请输入有无功，填写有或无!' }]},
        direction:{rules: [{ required: true, message: '请输入正反向，填写正或反!' }]},
        yuan:{rules: [{ required: true, message: '请输入合分元，单位是相，只填数值，不填写单位!' }]},
        testingVoltage:{rules: [{ required: true, message: '请输入实验电压，单位是伏，只填数值不写单位!' }]},
        testingCurrent:{rules: [{ required: true, message: '请输入测试电流，单位是安培，只填数值，不填写单位!' }]},
        powerFactor:{rules: [{ required: true, message: '请输入功率因数,供应商填写!' }]},
        averageError:{rules: [{ required: true, message: '请输入平均误差，如-0.0222!' }]},
        conclusion:{rules: [{ required: true, message: '请输入监测结论，0：合格，1：不合格!' }]},
        createTime:{rules: [{ required: true, message: '请输入创建时间/抓取时间，格式：YYYY-MM-DD!' }]},
        ioflag:{rules: [{ required: true, message: '请输入上传标志，默认1,1：未上传，0：已上传!' }]},
        jId:{rules: [{ required: true, message: '请输入jId!' }]},
        infoTypeCode:{},
        grabTime:{},
        },
        url: {
          add: "/zxjeipdnbjbwcdetail/zxjEipDnbJbwccsdetail/add",
          edit: "/zxjeipdnbjbwcdetail/zxjEipDnbJbwccsdetail/edit",
        }
     
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'supplierCode','productionOrderId','workOrderCode','testCode','plantCode','checkTime','power','direction','yuan','testingVoltage','testingCurrent','powerFactor','averageError','conclusion','createTime','ioflag','jId','infoTypeCode','grabTime'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'supplierCode','productionOrderId','workOrderCode','testCode','plantCode','checkTime','power','direction','yuan','testingVoltage','testingCurrent','powerFactor','averageError','conclusion','createTime','ioflag','jId','infoTypeCode','grabTime'))
      }
      
    }
  }
</script>